package com.dragon.gencode.conf.db;//package com.dragon.gencode.conf.db;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.context.annotation.Configuration;
//import org.sqlite.SQLiteConnection;
//
//import javax.annotation.PostConstruct;
//import java.sql.Connection;
//import java.sql.DriverManager;
//import java.sql.SQLException;
//import java.sql.Statement;
//
//// 本想 sqlite 不存在时 创建 sqlite 但是 不成功
//@Configuration
//@ConfigurationProperties(prefix = "spring.datasource.gen-sqlite")
//public class DataSourceHelper {
//
//    private Logger log = LoggerFactory.getLogger(DataSourceHelper.class);
//
//    private String driverClassName; // com.mysql.cj.jdbc.Driver
//    private String url; // jdbc:mysql://localhost:3306/pybbs?useSSL=false&characterEncoding=utf8
//    private String username; // root
//    private String password; // password
//
//    @PostConstruct
//    public void init() {
//        try {
//            SQLiteConnection
//            Class.forName(driverClassName);
//            String fileName = null;
//            if (url != null) {
//                fileName = url.substring(url.lastIndexOf("/")+1);
//            }else {
//                throw new RuntimeException("url is empty");
//            }
//            Connection connection = DriverManager.getConnection(url, username, password);
//            Statement statement = connection.createStatement();
//
//            statement.executeUpdate("CREATE DATABASE IF NOT EXISTS `" + fileName + "` DEFAULT CHARACTER SET = `utf8` COLLATE `utf8_general_ci`;");
//            statement.close();
//            connection.close();
//        } catch (ClassNotFoundException | SQLException e) {
//            e.printStackTrace();
//            log.error(e.getMessage());
//        }
//    }
//
//
//    public String getDriverClassName() {
//        return driverClassName;
//    }
//
//    public void setDriverClassName(String driverClassName) {
//        this.driverClassName = driverClassName;
//    }
//
//    public String getUrl() {
//        return url;
//    }
//
//    public void setUrl(String url) {
//        this.url = url;
//    }
//
//    public String getUsername() {
//        return username;
//    }
//
//    public void setUsername(String username) {
//        this.username = username;
//    }
//
//    public String getPassword() {
//        return password;
//    }
//
//    public void setPassword(String password) {
//        this.password = password;
//    }
//}